﻿<?php
//设置页面内容是html编码格式是utf-8
error_reporting(0);
header("Content-Type: text/html;charset=utf-8"); 
require_once '../swiftmailer-master/lib/swift_required.php';
require_once '../model/PdoMySQL.class.php';
require_once '../model/pwd.php';
if ($_SERVER["REQUEST_METHOD"] == "GET") {
	update();
}
function update(){
	$id = $_GET["id"];
	echo $id;
	if (!isset($_GET["id"]) || empty($_GET["id"])) {
		echo "参数错误";
		return;
	}
	
	$con = mysql_connect("localhost","root","playboy");
	if (!$con){
  		die('Could not connect: ' . mysql_error());
  	}
	$result='激活失败';
	mysql_select_db("db_pet", $con);
	mysql_query("UPDATE projector SET status = 1 WHERE id ={$id}");

	$res=mysql_query("select status from projector where id={$id}");
	$list_arr=mysql_fetch_object($res);
	$temp=$list_arr->status;
	mysql_close($con);

	if($temp==1){
		$result='成功激活';
		//break;
	}
	echo $result;
		try{
	$pdo=new PDO('mysql:host=localhost;dbname=db_pet','root','playboy');	
	$sql="select username from projector where id=".$id;
	$sql1="select email from projector where id=".$id;
	$stmt=$pdo->prepare($sql);
	$stmt1=$pdo->prepare($sql1);
	$stmt->execute();
	$stmt1->execute();
	
	while($row = $stmt->fetch()){
		$username=$row['username'];
		
	}
	while($row1 = $stmt1->fetch()){
		$email=$row1['email'];
		
	}
		//配置邮件服务器，得到传输对象
		$emailPassword='lbpplayboy';
		$transport=Swift_SmtpTransport::newInstance('smtp.qq.com',25);
		//设置登陆帐号和密码
		$transport->setUsername('704568245@qq.com');
		$transport->setPassword($emailPassword);
		//得到发送邮件对象Swift_Mailer对象
		$mailer=Swift_Mailer::newInstance($transport);
		//得到邮件信息对象
		$message=Swift_Message::newInstance();
		//设置管理员的信息
		$message->setFrom(array('704568245@qq.com'=>'动物管理系统'));
		//将邮件发给谁
		$message->setTo(array($email=>'动物管理系统用户'));
		//设置邮件主题
		$message->setSubject('密码找回邮件');
		$str=<<<EOF
		亲爱的用户{$username}您好,您的账户已成功激活，感谢您使用本网站。<br/>
EOF;
		$message->setBody("{$str}",'text/html','utf-8');
		try{
			if($mailer->send($message)){
			echo'<script language="JavaScript">window.location.href="form-wizard.php";</script>';
			
			}else{
				echo '邮件发送失败';
				echo'<script language="JavaScript">window.location.href="form-wizard.php";</script>';
			}
		}catch(Swift_ConnectionException $e){
			echo '邮件发送错误'.$e->getMessage();
		}
	}
	catch(PDOException $e){
	echo $e->getMessage();
	}
}


